import { HttpRequest } from "@/utils/requests";

export const postLogin = (data) => {
  return HttpRequest.post("/api/login", data);
};

export const postRegister = (data) => {
  return HttpRequest.post("/api/register", data);
};

export const postVerify = (data) => {
  return HttpRequest.post("/api/verifytoken", data);
};

// 分类接口
export const getCategoryList = () => {
  return HttpRequest.get("/category/list");
};

export const getCategoryName = (id) => {
  return HttpRequest.get(`/category/${id}`);
};

// 文章接口
export const postArticle = (data) => {
  return HttpRequest.post("/article/add", data);
};

export const postEditArticle = (data) => {
  return HttpRequest.post("/article/edit", data);
};

export const getArticleList = () => {
  return HttpRequest.get("/article/list");
};

export const getArticleDetail = (id) => {
  return HttpRequest.get(`/article/detail/${id}`);
};

export const deleteArticle = (data) => {
  return HttpRequest.post("/article/delete", data);
};

//点赞接口
export const postLike = (data) => {
  return HttpRequest.post(`/article/like/${data.articleId}`, data);
};

//用户接口
export const getUserInfo = (id) => {
  return HttpRequest.get(`/api/info/${id}`);
};

export const getUserArticles = (data) => {
  return HttpRequest.get(`/api/articles/${data.userId}`);
};

export const updateUserInfo = (data) => {
  console.log(data);

  return HttpRequest.post(`/user/updateInfo`, data);
};

export const updatePassword = (data) => {
  return HttpRequest.post(`/user/updatePassword`, data);
};
